package com.coder520.user.controller;

import com.coder520.user.entity.User;
import com.coder520.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017-7-7.
 */
@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/index")
    public String user() {

        return "/login";
    }

    @RequestMapping("/home")
    public String home() {

        return "home";
    }


    /**
      *@Author Jay
      *@Date 2017-7-8 20:33
      *@Description 获取用户信息
      */
    @RequestMapping("/userInfo")
    @ResponseBody
    public User getUser(HttpSession session) {
        User user = (User) session.getAttribute("userInfo");
        return user;
    }

    /**
      *@Author Jay
      *@Date 2017-7-8 21:54
      *@Description    退出登入
      */
    @RequestMapping("/logout")
    public String logout(HttpSession session) {
        session.invalidate();
        return "/login";
    }

}
